import request from '../utils/request';

export const api = {
  // 验证码相关
  getVerifyCode: () => request.get('/sys/getVerify'),

  // 用户认证相关
  login: (data) => request.post('/sys/user/login', data),
  logout: () => request.get('/sys/user/logout'),
  register: (data) => request.post('/sys/user/register', data),

  // 首页相关
  getHomeInfo: () => request.get('/sys/home'),

  // 用户信息相关
  getUserInfo: () => request.get('/sys/user'), // 获取当前用户信息
  getUserById: (id) => request.get(`/sys/user/${id}`), // 获取指定用户信息
  updateUserInfo: (data) => request.put('/sys/user/info', data), // 用户更新个人信息
  updateUser: (data) => request.put('/sys/user', data), // 管理员更新用户信息
  updatePassword: (data) => request.put('/sys/user/pwd', data),

  // 用户管理相关
  getUserList: (params) => request.post('/sys/users', params), // 分页获取用户列表
  addUser: (data) => request.post('/sys/user', data),
  deleteUser: (userIds) => request.delete('/sys/user', { data: userIds }),

  // 用户角色相关
  getUserRoles: (userId) => request.get(`/sys/user/roles/${userId}`),
  setUserRoles: (userId, roleIds) => request.put(`/sys/user/roles/${userId}`, roleIds),
  addUserRole: (data) => request.post('/sys/user/role', data),

  // 网络拓扑相关
  loadTopology: (file) => {
    const formData = new FormData();
    formData.append('file', file);
    return request.post('/network/load', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },
  loadDefaultTopology: () => request.get('/network/defaultLoad'),
  getTopologyHistory: () => request.get('/network/topology/history'),
  loadHistoryTopology: (id) => request.post(`/network/topology/load/${id}`),
  clearNetwork: () => request.delete('/network/clear'),
  getAttackerCount: () => request.get('/network/attackerCount'),
  getServerCount: () => request.get('/network/serverCount'),
  executeAttack: (data) => request.post('/network/attack', data),
  getServerTraffic: (serverName) => request.post('/network/serverTraffic', serverName, {
    headers: {
      'Content-Type': 'text/plain; charset=UTF-8'
    }
  }),
  verifyAttack: (attackerName, targetName) => request.post('/network/verifyAttack', {
    attackerName,
    targetName
  }),
};
